include ../Makefile
.PHONY: FSM_bin keyboard_sim

FSM_bin: TOPMODULE=FSM_bin
FSM_bin: vsrc=FSM_bin.v muxkey.v
FSM_bin: top

keyboard_sim: VERILATOR_FLAG+= --trace-fst --timescale-override 1ns/1ps
keyboard_sim: TOPMODULE=keyboard_sim
keyboard_sim: vsrc=keyboard_sim.v ps2_keyboard_model.v ps2_keyboard.v
keyboard_sim: VERILATOR_FLAG+=--timing
#	--timescale 1ns/100ps
keyboard_sim: top

scanasciilower.txt: ascii.txt scancode2lower.txt 
	python3 merge.py $^ scancode2upper.txt scancode2multi.txt $@
scancode2lower.txt: scancode.txt 
	python3 transfer.py $^ $@  scancode2upper.txt scancode2multi.txt
scancode.txt: scancode.html
	sed -n "/Key No/,/<\/TABLE><\/H3>/p" $^ | head -n -1| tail -n +18 | grep "FONT" | sed -E "s/&nbsp;//g;s/&lt;/</g;s/&gt;/>/g;s/&amp;/\&/g;s/&quot;/\"/g" | sed "367{N;s/\r\n//};393{N;s/\r\n//};537{N;s/\r\n//}" | sed -E "s/.+<FONT.+>(.+)[\n]?(.*)<\/FONT>.+/\1 \2/"> $@
scancode.html:
	curl 'https://www.vetra.com/scancodes.html' -o $@
ascii.html:
	curl 'https://www.ascii-code.com/ASCII' -o $@
ascii.txt: ascii.html
	sed -n "/<tbody>/,/<\/tbody>/p" $^ | sed "s/\r\n/\n/g;s/<\/tr>/\n/g;s/<tr>//g;s/<\/td>/\n/g" | grep "<td>"|sed -E "s/<td>(.*?)/\1/g;s/<a.*>(.+)<\/a>/\1/" >$@

